import React from 'react'
import { Redirect, Route, Switch } from 'react-router-dom'

function index(props) {
    const routerRedirect = props.routes.filter(item => item.redirect).map((item, index) => <Redirect from={item.path} to={item.redirect} key={index} />)
    const routerRoute = props.routes.filter(item => item.component)
    return (
        <Switch>
            {
                routerRoute.map((item, index) => {
                    return (
                        <Route
                            path={item.path}
                            key={index}
                            render={(props) => {
                                if(item.children){
                                    return <item.component {...props} routes={item.children} />
                                }
                                return <item.component {...props} />
                            }}
                        />
                    )
                }).concat(routerRedirect)
            }
        </Switch>
    )
}

export default index
